<?php
defined('IN_IA') or exit('Access Denied');
global $_W, $_GPC;
set_time_limit(600);
$uniacid = $_W['uniacid'];
$pindex = $_GPC['page'];
if (empty($pindex) || $pindex <= 0) {
	$pindex = 1;
	$_GPC['page'] = 1;
}
$psize = 50;
$list = pdo_fetchall("SELECT id,quan_link FROM " . tablename($this->tableitemall) . " WHERE uniacid = '{$_W['uniacid']}' order by displayorder desc,id desc,atime desc LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
if ($list) {
	foreach ($list as $key => $value) {
		$ch = curl_init();
		$timeout = 10;
		curl_setopt($ch, CURLOPT_URL, $list[$key]['quan_link']);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D257 QQ/5.2.1.302 NetType/WIFI Mem/28");
		$html = curl_exec($ch);
		curl_close($ch);
		if ($html) {
			$uls = $this->getTags($html, "div class=\"sale-info\"");
			if (isset($uls[0]['s'])) {
				$content = substr($html, $uls[0]['s'], $uls[0]['e']);
				if (strpos($content, "不存在") > 0) {
					$newdata = array();
					$newdata['status'] = 0;
					pdo_update($this->tableitemall, $newdata, array('id' => $list[$key]['id']));
				}
			}
		}
	}
	$pindex++;
	message('第' . $_GPC['page'] . '页清理完毕，即将清理第' . $pindex . '页（每页50条），请稍后。。。', $this->createWebUrl('yhj_all_op', array('page' => $pindex)), 'success');
}
message('操作成功！全部过期优惠券已被下架处理，即将清空所有下架商品！', $this->createWebUrl('itemall_op', array('op' => 'show_none')), 'success');